////////////////////////////////////////////////////////////////////////////////
// Copyright 2005 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   MENU_GROUP_LABEL
// AUTHOR           :   Victor Zheng 
// DATE CREATE      :   2005/12/21
// DESCRIPTION      :   a FORM file for the function, MENU_GROUP_LABEL
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2005/12/21   Victor Zheng    1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.admin.menuGroupLabel.web;

import java.util.ArrayList;
import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.app.common.select.beans.SelectDelegate;
import com.erp.app.setup.codeSetup.web.CodeDtlRow;
import com.erp.framework.controller.form.SimplePageEditStyleForm;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.logger.Logger;

/**
* <p>A <strong>PageEditForm</strong> is a JavaBean which provides property
* getter and setter methods for all of the bean properties, and implements
* <code>Serializable</code>, as required by the JavaBean specification
* The main purpose for this bean is to get the user search criteria input
* and to get the user input from the web browsers.
* from the web browsers.
* As the name implies, it will only handle one-page-edit documents.
*
* @author          Victor Zheng 
* @version 1.0     2005/12/21
* @since           FrameWork 1.0
*
*/
public class MenuGroupLabelForm extends SimplePageEditStyleForm {

	//Attributes (DB Table Name: T_MENU_GROUP_LABEL)
	private String[] companyCode;                    //DB Column Name: COMPANY_CODE
	private String[] groupId;                        //DB Column Name: GROUP_ID
	private String[] menuId;                         //DB Column Name: MENU_ID
	private String[] langCode;                       //DB Column Name: LANG_CODE
	private String[] menuName;                       //DB Column Name: MENU_NAME
	private String[] menuWebLabel;                   //DB Column Name: MENU_WEB_LABEL
	private String[] createUser;                     //DB Column Name: CREATE_USER
	private String[] createDate;                     //DB Column Name: CREATE_DATE
	private String[] updateUser;                     //DB Column Name: UPDATE_USER
	private String[] updateDate;                     //DB Column Name: UPDATE_DATE
	private String[] menuType;                       //DB Column Name: MENU_TYPE

	//Searching Criteria Attributes (DB Table Name: T_MENU_GROUP_LABEL)
	private String srchCompanyCode;                  //DB Column Name: COMPANY_CODE
	private String srchStatus;                       //DB Column Name: STATUS
    /*
	private String srchGroupIdFr;                    //DB Column Name: GROUP_ID
	private String srchGroupIdTo;                    //DB Column Name: GROUP_ID
	private String srchMenuIdFr;                     //DB Column Name: MENU_ID
	private String srchMenuIdTo;                     //DB Column Name: MENU_ID
	private String srchLangCodeFr;                   //DB Column Name: LANG_CODE
	private String srchLangCodeTo;                   //DB Column Name: LANG_CODE
	private String srchMenuNameFr;                   //DB Column Name: MENU_NAME
	private String srchMenuNameTo;                   //DB Column Name: MENU_NAME
	private String srchMenuWebLabelFr;               //DB Column Name: MENU_WEB_LABEL
	private String srchMenuWebLabelTo;               //DB Column Name: MENU_WEB_LABEL
    */
    private String srchGroupId;
    private String srchMenuId;
    private String srchLangCode;
    private String srchMenuName;
    private String srchMenuWebLabel;

	/**
	* Converts to a string representing the data in this object.
	* A new <code>String</code> object is allocated and initialized to 
	* contain the character sequence currently represented by this 
	* object. This <code>String</code> is then returned. Subsequent 
	* changes to this object do not affect the contents of the 
	* <code>String</code>. 
	*
	* @return     a string representation of the object.
	* @see        java.lang.Object#toString()
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public String toString() {
		/*String pkStr = "PK: {srchGroupIdFr = " + this.srchGroupIdFr
			+ "\n, srchGroupIdTo = " + this.srchGroupIdTo
			+ "\n, srchMenuIdFr = " + this.srchMenuIdFr
			+ "\n, srchMenuIdTo = " + this.srchMenuIdTo
			+ "\n, srchLangCodeFr = " + this.srchLangCodeFr
			+ "\n, srchLangCodeTo = " + this.srchLangCodeTo + "}\n";

		String colStr = "COL: {srchMenuNameFr = " + this.srchMenuNameFr
			+ "\n, srchMenuNameTo = " + this.srchMenuNameTo
			+ "\n, srchMenuWebLabelFr = " + this.srchMenuWebLabelFr
			+ "\n, srchMenuWebLabelTo = " + this.srchMenuWebLabelTo + "}\n";

		String mandatoryStr = "{srchCompanyCode = " + this.srchCompanyCode
			+ "\n, srchStatus = " + this.srchStatus
			+ "}\n";
        */
        String pkStr = "PK: {srchGroupId = " + this.srchGroupId
        + "\n, srchMenuId = " + this.srchMenuId
        + "\n, srchLangCode = " + this.srchLangCode + "}\n";

        String colStr = "COL: {srchMenuName = " + this.srchMenuName
            + "\n, srchMenuWebLabel = " + this.srchMenuWebLabel + "}\n";
    
        String mandatoryStr = "{srchCompanyCode = " + this.srchCompanyCode
            + "\n, srchStatus = " + this.srchStatus
            + "}\n";

		return "toString() is:\n" + mandatoryStr + pkStr + colStr;
	}

	
	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      the action errors array
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void validateSearch(ActionErrors errors) {

		/*
		ArrayList rows = getMultiRows(0);

		for (int i = 0; rows != null && i < rows.size(); i++) {
			MenuGroupLabelRow row = (MenuGroupLabelRow) rows.get(i);

			if (CommonUtil.isEmpty(row.getShipDate())) {
				ActionErrorUtil.addErrorForGeneralFieldBlank(errors, "Ship Date");
			} else {
				if (!CommonUtil.isValidDate(row.getShipDate())) {
					ActionErrorUtil.addErrorForInvalidDate(errors, "Ship Date");
				}
			}
		}
		*/
	}

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      mapping      the action mapping
	* @param      formIn       the action form
	* @param      request      the http request
	* @param      response     the http response
	* @param      errors       the action errors array
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void moreValidateSearch(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {


		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	/**
	* Reset all bean properties to their default state.  This method
	* is called inside the reset() method.
	*
	* @param      mapping The mapping used to select this instance
	* @param      request The servlet request we are processing
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void otherReset(ActionMapping mapping, HttpServletRequest request) {

		setRowMode(null);
		setIdx(null);
		//companyCode = null;
		//srchCompanyCode = null;
	}

	////////////////////////////////////////////////////////////////////////////////
	//Generated Accessors (get/set methods) for Table (MenuGroupLabel)
	////////////////////////////////////////////////////////////////////////////////

	public String[] getCompanyCode() {
		return this.companyCode;
	}

	public String[] getGroupId() {
		return this.groupId;
	}

	public String[] getMenuId() {
		return this.menuId;
	}

	public String[] getLangCode() {
		return this.langCode;
	}

	public String[] getMenuName() {
		return this.menuName;
	}

	public String[] getMenuWebLabel() {
		return this.menuWebLabel;
	}

	public String[] getCreateUser() {
		return this.createUser;
	}

	public String[] getCreateDate() {
		return this.createDate;
	}

	public String[] getUpdateUser() {
		return this.updateUser;
	}

	public String[] getUpdateDate() {
		return this.updateDate;
	}

	public String[] getMenuType() {
		return this.menuType;
	}

	public void setCompanyCode(String[] companyCode) {
		this.companyCode = companyCode;
	}

	public void setGroupId(String[] groupId) {
		this.groupId = groupId;
	}

	public void setMenuId(String[] menuId) {
		this.menuId = menuId;
	}

	public void setLangCode(String[] langCode) {
		this.langCode = langCode;
	}

	public void setMenuName(String[] menuName) {
		this.menuName = menuName;
	}

	public void setMenuWebLabel(String[] menuWebLabel) {
		this.menuWebLabel = menuWebLabel;
	}

	public void setCreateUser(String[] createUser) {
		this.createUser = createUser;
	}

	public void setCreateDate(String[] createDate) {
		this.createDate = createDate;
	}

	public void setUpdateUser(String[] updateUser) {
		this.updateUser = updateUser;
	}

	public void setUpdateDate(String[] updateDate) {
		this.updateDate = updateDate;
	}

	public void setMenuType(String[] menuType) {
		this.menuType = menuType;
	}

	////////////////////////////////////////////////////////////////////////////////
	//Generated Accessors (get/set methods) for searching criterias
	////////////////////////////////////////////////////////////////////////////////

	public String getSrchCompanyCode() {
		return this.srchCompanyCode;
	}

	public String getSrchStatus() {
		return this.srchStatus;
	}
    
    public String getSrchGroupId() {
        return this.srchGroupId;
    }

    public String getSrchMenuId() {
        return this.srchMenuId;
    }
    
    public String getSrchLangCode() {
        return this.srchLangCode;
    }
    
    public String getSrchMenuName() {
        return this.srchMenuName;
    }
    
    public String getSrchMenuWebLabel() {
        return this.srchMenuWebLabel;
    }
    
    public void setSrchCompanyCode(String srchCompanyCode) {
        this.srchCompanyCode = srchCompanyCode;
    }

    public void setSrchStatus(String srchStatus) {
        this.srchStatus = srchStatus;
    }

    public void setSrchGroupId(String srchGroupId) {
        this.srchGroupId = srchGroupId;
    }
    
    public void setSrchMenuId(String srchMenuId) {
        this.srchMenuId = srchMenuId;
    }
    
    public void setSrchLangCode(String srchLangCode) {
        this.srchLangCode = srchLangCode;
    }

    public void setSrchMenuName(String srchMenuName) {
        this.srchMenuName = srchMenuName;
    }

    public void setSrchMenuWebLabel(String srchMenuWebLabel) {
        this.srchMenuWebLabel = srchMenuWebLabel;
    }

	/*public String getSrchGroupIdFr() {
		return this.srchGroupIdFr;
	}

	public String getSrchGroupIdTo() {
		return this.srchGroupIdTo;
	}

	public String getSrchMenuIdFr() {
		return this.srchMenuIdFr;
	}

	public String getSrchMenuIdTo() {
		return this.srchMenuIdTo;
	}

	public String getSrchLangCodeFr() {
		return this.srchLangCodeFr;
	}

	public String getSrchLangCodeTo() {
		return this.srchLangCodeTo;
	}

	public String getSrchMenuNameFr() {
		return this.srchMenuNameFr;
	}

	public String getSrchMenuNameTo() {
		return this.srchMenuNameTo;
	}

	public String getSrchMenuWebLabelFr() {
		return this.srchMenuWebLabelFr;
	}

	public String getSrchMenuWebLabelTo() {
		return this.srchMenuWebLabelTo;
	}

	public void setSrchCompanyCode(String srchCompanyCode) {
		this.srchCompanyCode = srchCompanyCode;
	}

	public void setSrchStatus(String srchStatus) {
		this.srchStatus = srchStatus;
	}

	public void setSrchGroupIdFr(String srchGroupIdFr) {
		this.srchGroupIdFr = srchGroupIdFr;
	}

	public void setSrchGroupIdTo(String srchGroupIdTo) {
		this.srchGroupIdTo = srchGroupIdTo;
	}

	public void setSrchMenuIdFr(String srchMenuIdFr) {
		this.srchMenuIdFr = srchMenuIdFr;
	}

	public void setSrchMenuIdTo(String srchMenuIdTo) {
		this.srchMenuIdTo = srchMenuIdTo;
	}

	public void setSrchLangCodeFr(String srchLangCodeFr) {
		this.srchLangCodeFr = srchLangCodeFr;
	}

	public void setSrchLangCodeTo(String srchLangCodeTo) {
		this.srchLangCodeTo = srchLangCodeTo;
	}

	public void setSrchMenuNameFr(String srchMenuNameFr) {
		this.srchMenuNameFr = srchMenuNameFr;
	}

	public void setSrchMenuNameTo(String srchMenuNameTo) {
		this.srchMenuNameTo = srchMenuNameTo;
	}

	public void setSrchMenuWebLabelFr(String srchMenuWebLabelFr) {
		this.srchMenuWebLabelFr = srchMenuWebLabelFr;
	}

	public void setSrchMenuWebLabelTo(String srchMenuWebLabelTo) {
		this.srchMenuWebLabelTo = srchMenuWebLabelTo;
	}*/

	////////////////////////////////////////////////////////////////////////////////
	//Other Accessors (get/set methods)
	////////////////////////////////////////////////////////////////////////////////
    public ArrayList  getCodeDtlDropdownCollection(String shareCompanyCode, 
            String  refMasterCode, 
            String  columnValue, 
            boolean  isCriteriaSearch){ 

        ArrayList collection = new  ArrayList();
        
        SelectDelegate  selectDelegate = new SelectDelegate();   
        String whereClause =  " hdr.REF_MASTER_CODE='" + refMasterCode + "'  " 
        + " AND hdr.COMPANY_CODE = '" +  shareCompanyCode + "' " 
        + " AND  hdr.COMPANY_CODE = dtl.COMPANY_CODE " 
        +  " AND hdr.REF_MASTER_CODE = dtl.REF_MASTER_CODE  " 
        + (isCriteriaSearch?"":(" AND  (dtl.REF_STATUS = '"+ProjectConstants.GENERIC_ACTIVE+"' OR dtl.REF_CODE = '" +  columnValue + "')")); 
        String codeDesc = "  decode(nvl(hdr.SHOW_DESC, '"+ProjectConstants.GENERIC_YES+"'),  '"+ProjectConstants.GENERIC_YES+"', dtl.REF_DESC, dtl.REF_CODE)"; 
        
        String  srchTableName = "T_CODE_DTL dtl, T_CODE_HDR hdr"; 
        
        String[]  srchColumn = new String[2]; 
        srchColumn[0] = " dtl.REF_CODE AS CODE  "; 
        srchColumn[1] = codeDesc + " AS  DESCRIPTION "; 
        
        ArrayList result = new ArrayList();
        Hashtable row =  new Hashtable(); 
        result = selectDelegate.findFieldList( srchTableName, srchColumn,  whereClause); 
        
        CodeDtlRow cdr =  new CodeDtlRow(); 
        for (int i = 0 ;  result.size() > 0 && i < result.size() ; i++  ){ 
            row =  (Hashtable)result.get(i); 
            cdr = new  CodeDtlRow(); 
            
            cdr.setCompanyCode(shareCompanyCode); 
            cdr.setRefMasterCode(refMasterCode); 
            cdr.setRefCode(CommonUtil.nullToString(row.get("CODE"))); 
            cdr.setDtlRefDesc(CommonUtil.nullToString(row.get("DESCRIPTION"))); 
            
            collection.add(cdr); 
        }  
        return  collection; 
    }
}